package com.qymerge.manage.base.service.impl;

import com.qymerge.manage.base.dao.IBDMSaleLinesDao;
import com.qymerge.manage.base.dao.IMetaLogsDao;
import com.qymerge.manage.base.dao.IStoredProcedureDao;
import com.qymerge.manage.base.ro.BDMSaleLinesRO;
import com.qymerge.manage.base.ro.MetaLogsRO;
import com.qymerge.manage.base.service.IStoredProcedureService;
import com.qymerge.manage.core.bean.ActionResultRO;
import com.qymerge.manage.core.bean.DataTableRO;
import com.qymerge.manage.core.bean.PageRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 *
 * @author Xiao
 * @version 1.0.0
 * @date 2025/5/28 17:32
 */
@Service
public class StoredProcedureServiceImpl implements IStoredProcedureService {

    @Autowired
    private IBDMSaleLinesDao saleLinesDao;
    @Autowired
    private IStoredProcedureDao storedProcedureDao;
    @Autowired
    private IMetaLogsDao metaLogsDao;

    @Override
    public ActionResultRO listBDMSaleLines(BDMSaleLinesRO ro, PageRequest pageRequest) {
        // 记录开始时间
        Long beginTime = System.currentTimeMillis();
        List<BDMSaleLinesRO> list = storedProcedureDao.getBDMSaleLinesByBillCode(ro.getBillCode(), pageRequest.getPage(), pageRequest.getSize());
        // 记录结束时间
        Long endTime = System.currentTimeMillis();
        long timeDifference = (endTime-beginTime) / 1000;// 耗时计算（秒）
        metaLogsDao.install(new MetaLogsRO("getBDMSaleLinesByBillCode", beginTime, endTime, timeDifference));
        return new ActionResultRO(true, "ok", list);
    }

    @Override
    public ActionResultRO dwd_MCRS_MDM_sp_Voucher(BDMSaleLinesRO ro, PageRequest pageRequest) {
        // 记录开始时间
        Long beginTime = System.currentTimeMillis();
        // 执行存储过程
        storedProcedureDao.dwd_MCRS_MDM_sp_Voucher(ro.getPeriodCode());
        // 记录结束时间
        Long endTime = System.currentTimeMillis();
        long timeDifference = (endTime-beginTime) / 1000;// 耗时计算（秒）
        metaLogsDao.install(new MetaLogsRO("dwd_MCRS_MDM_sp_Voucher", beginTime, endTime, timeDifference));

        return new ActionResultRO(true, "ok");
    }

    @Override
    public ActionResultRO dwd_MCRS_BDM_sp_SaleLines(BDMSaleLinesRO ro, PageRequest pageRequest) {
        // 记录开始时间
        Long beginTime = System.currentTimeMillis();
        // 执行存储过程
        storedProcedureDao.dwd_MCRS_BDM_sp_SaleLines(ro.getPeriodCode());
        // 记录结束时间
        Long endTime = System.currentTimeMillis();
        long timeDifference = (endTime-beginTime) / 1000;// 耗时计算（秒）
        metaLogsDao.install(new MetaLogsRO("dwd_MCRS_BDM_sp_SaleLines", beginTime, endTime, timeDifference));

        return new ActionResultRO(true, "ok");
    }

    @Override
    public ActionResultRO dwd_MCRS_MDM_Sp_ActualDataExtra(BDMSaleLinesRO ro, PageRequest pageRequest) {
        // 记录开始时间
        Long beginTime = System.currentTimeMillis();
        // 执行存储过程
        storedProcedureDao.dwd_MCRS_MDM_Sp_ActualDataExtra(ro.getPeriodCode());
        // 记录结束时间
        Long endTime = System.currentTimeMillis();
        long timeDifference = (endTime-beginTime) / 1000;// 耗时计算（秒）
        metaLogsDao.install(new MetaLogsRO("dwd_MCRS_MDM_Sp_ActualDataExtra", beginTime, endTime, timeDifference));

        return new ActionResultRO(true, "ok");
    }

    @Override
    public ActionResultRO dwd_MCRS_MDM_sp_InventoryBalance(BDMSaleLinesRO ro, PageRequest pageRequest) {
        // 记录开始时间
        Long beginTime = System.currentTimeMillis();
        // 执行存储过程
        storedProcedureDao.dwd_MCRS_MDM_sp_InventoryBalance(ro.getPeriodCode());
        // 记录结束时间
        Long endTime = System.currentTimeMillis();
        long timeDifference = (endTime-beginTime) / 1000;// 耗时计算（秒）
        metaLogsDao.install(new MetaLogsRO("dwd_MCRS_MDM_sp_InventoryBalance", beginTime, endTime, timeDifference));

        return new ActionResultRO(true, "ok");
    }

    @Override
    public ActionResultRO dwd_MCRS_Report_SP_In_Out_Cost(BDMSaleLinesRO ro, PageRequest pageRequest) {
        // 记录开始时间
        Long beginTime = System.currentTimeMillis();
        // 执行存储过程
        storedProcedureDao.dwd_MCRS_Report_SP_In_Out_Cost();
        // 记录结束时间
        Long endTime = System.currentTimeMillis();
        long timeDifference = (endTime-beginTime) / 1000;// 耗时计算（秒）
        metaLogsDao.install(new MetaLogsRO("dwd_MCRS_Report_SP_In_Out_Cost", beginTime, endTime, timeDifference));

        return new ActionResultRO(true, "ok");
    }

    @Override
    public ActionResultRO dwd_MCRS_Report_SP_In_Sales(BDMSaleLinesRO ro, PageRequest pageRequest) {

        // 记录开始时间
        Long beginTime = System.currentTimeMillis();
        // 执行存储过程
        storedProcedureDao.dwd_MCRS_Report_SP_In_Sales();
        // 记录结束时间
        Long endTime = System.currentTimeMillis();
        long timeDifference = (endTime-beginTime) / 1000;// 耗时计算（秒）
        metaLogsDao.install(new MetaLogsRO("dwd_MCRS_Report_SP_In_Sales", beginTime, endTime, timeDifference));

        return new ActionResultRO(true, "ok");
    }

}
